﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using AddressBook.DAO;

namespace AddressBookSynApp
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                SynDataService.SynDataServiceSoapClient client = new SynDataService.SynDataServiceSoapClient();
                DataTable dtDeptid = Globle.GetSQLDataTable("select left(deptid,4) from [Base_Dept] group by left(deptid,4)");
                DataTable dtDept = Globle.GetSQLDataTable("select * from Base_Dept with(nolock)");
                dtDept.TableName = "Base_Dept";
                DataTable dtEmployees = Globle.GetSQLDataTable("select * from Base_Employee with(nolock)");
                dtEmployees.TableName = "Base_Employee";

                if (dtDeptid.Rows.Count > 0)
                {
                    string deptids = string.Empty;
                    foreach (DataRow dr in dtDeptid.Rows)
                    {
                        deptids += "'" + dr[0].ToString() + "',";
                    }
                    deptids = deptids.Remove(deptids.Length - 1);

                    if (client.SynEmployeesDepts(dtEmployees, dtDept, deptids))
                    {
                        //ToDo Over
                        Console.WriteLine("Completed....");
                    }
                    else
                    {
                        Console.WriteLine("Not Completed....");
                    }
                }
                else
                {
                    Console.WriteLine("Empty Data....");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error:" + ex);
            }
        }
    }
}
